package com.hankol.community

import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.baselibrary.MessageBus
import com.baselibrary.activity.BaseActivity
import com.baselibrary.extension.checkValue
import com.baselibrary.manager.SensorsDataManager
import com.baselibrary.router.ActivityRouter
import com.baselibrary.utils.SpUtils
import com.hankol.community.databinding.ActivityWineryFoodBinding
import com.hankol.community.viewmodel.CommunityViewModel
import com.hankol.feature_wine_meal.HomeWineFoodFragment
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

/**下酒菜 主页（首页大改版）
 * @author: merbng
 * @description:
 */
@Route(path = ActivityRouter.COMMUNITY.WINERY_FOOD)
class WineryFoodActivity : BaseActivity(), View.OnClickListener {

    private lateinit var viewModel: CommunityViewModel
    private lateinit var binding: ActivityWineryFoodBinding
    override fun getLayoutId(): Int {
        return R.layout.activity_winery_food
    }

    override fun init() {
        setStatusBarHeight(R.color.color_F9F9F9)
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this)
        }
        binding = getDataBinding()
        viewModel = getActivityViewModelProvider(this).get(CommunityViewModel::class.java)
        initView()
        initListener()
        initObserver()
        SensorsDataManager.instance.xfoodView()
    }

    private fun initListener() {
        binding.imgBack.setOnClickListener(this)
    }

    private fun initView() {
        supportFragmentManager.beginTransaction().add(R.id.fl_container, HomeWineFoodFragment.newInstance()).commit()
    }

    private fun initObserver() {
        binding.llLoading.postDelayed(Runnable {
            //解决华为手机闪一下
            binding.llLoading.visibility = View.GONE
        }, 200)
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.img_back -> {
                finish()
            }
        }
    }

    //EventBus 接受方法
    @Subscribe(threadMode = ThreadMode.MAIN) fun onEvent(messageBus: MessageBus) {

    }

    override fun onDestroy() {
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this)
        }
        super.onDestroy()
    }
}